package service

import (
	"context"
	"video-srv/basic/config"
	__ "video-srv/basic/proto/rpc"
	"video-srv/handler/model"
)

func (s *VideoServer) AddComment(_ context.Context, in *__.AddCommentReq) (*__.AddCommentResp, error) {
	comment := model.Comment{
		VideoId: int(in.VideoId),
		UserId:  int(in.UserId),
		Content: in.Content,
		Pid:     int(in.Pid),
	}
	err := comment.AddComment(config.DB)
	if err != nil {
		return nil, err
	}
	return &__.AddCommentResp{
		CommentId: int64(comment.ID),
	}, nil
}
func (s *VideoServer) GetCommentList(_ context.Context, in *__.GetCommentListReq) (*__.GetCommentListResp, error) {
	comment := model.Comment{}
	list, err := comment.GetComment(config.DB, int(in.VideoId))
	if err != nil {
		return nil, err
	}
	return &__.GetCommentListResp{
		List: list,
	}, nil
}
